﻿/*******************************************************************************
 * Copyright © 2017 FriendStar.Framework 版权所有
 * Author: FZH
 * Description: FriendStar快速开发平台
 * Website：http://www.FriendStar.cn
*********************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using SqlSugarRepository;
using FriendStar.Code;
using FriendStar.Domain.Entity.MainData;
using FriendStar.Domain.IRepository.MainData;
using FriendStar.Repository.MainData;

namespace FriendStar.Application.MainData
{
    /// <summary>
	/// 数据视图 V_BUS_SJ_Dictionary 对应的数据应用功能类。
	/// </summary>
	public class V_BUS_SJ_DictionaryApp
    {       
        private string UseUnit = Configs.GetValue("UseUnit");  

        private IV_BUS_SJ_DictionaryRepository service = new V_BUS_SJ_DictionaryRepository();

        public List<V_BUS_SJ_DictionaryEntity> GetList(Pagination pagination, string keyword)
        {
            var expression = ExtLinq.True<V_BUS_SJ_DictionaryEntity>();
            expression = expression.And(t => t.UseUnit == UseUnit);
            if (!string.IsNullOrEmpty(keyword))
            {
                expression = expression.And(t => t.FTypeNO.Contains(keyword));
            }
            return service.FindList(expression, pagination);
        }

        public List<V_BUS_SJ_DictionaryEntity> GetListByClassNo(string classNo)
        {
            var expression = ExtLinq.True<V_BUS_SJ_DictionaryEntity>();
            expression = expression.And(t => t.UseUnit == UseUnit);
            expression = expression.And(t => t.FClassNO == classNo);
            Pagination pagination = new Pagination();
            pagination.page = 1;
            pagination.rows = int.MaxValue;
            pagination.sidx = "FTypeNO";
            pagination.sord = "ASC";
            return service.FindList(expression, pagination);
        }

        public V_BUS_SJ_DictionaryEntity GetForm(string keyValue)
        {
            var expression = ExtLinq.True<V_BUS_SJ_DictionaryEntity>();
            expression = expression.And(t => t.FTypeID == keyValue);
            return service.FindEntity(expression);
        }

        public List<V_BUS_SJ_DictionaryEntity> GetEquipLineList()
        {
            string sql = string.Format("SELECT FTypeNO, FTypeName FROM  V_BUS_SJ_Dictionary  WHERE  (UseUnit = '{0}') AND (FClassNO = '25') and (FTypeNO='XA' OR FTypeNO='XB' OR FTypeNO='XC'  OR FTypeNO='XD')  ORDER  BY FTypeNO", UseUnit);
            return service.FindList(sql);
        }
    }
}